﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PccCommonForC;
using System.Text.RegularExpressions;
using System.IO;

public partial class Manager_Signature_Signature : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["AdminUserID"] == null)
        {
            Response.Write("<script language=javascript>alert('Time is out.');window.open('../Default.aspx','_top');</script>");
            return;
        }
        clsGetMenuAuth clsAuth = new clsGetMenuAuth(Session["AdminUserID"].ToString(), Session["AutID"].ToString(), Session["IsAdmin"].ToString(), Request.QueryString["CodeID"]);
        if (clsAuth.IsAddAuth() == false)
            btnSave.Visible = false;
        if (!IsPostBack)
            BindData();
    }

    private void BindData()
    {
        System.Web.UI.WebControls.Image myImage = new System.Web.UI.WebControls.Image();
      /*  myImage.Width = Unit.Pixel(100);
        myImage.Height = Unit.Pixel(100);*/
        myImage.ImageUrl = "UserSignImages.aspx";
        pnlSign.Controls.Add(myImage);
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (FileU_HinhMinhHoa.HasFile)
        {
            Regex objRegex = new Regex(@"(.*?)\.jpg|(.*?)\.png|(.*?)\.gif|(.*?)\.bmp");
            if (!objRegex.IsMatch(FileU_HinhMinhHoa.FileName.ToLower()))
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('Chọn file hình ảnh')</script>");
                return;
            }
            else
            {
                Stream fileStream = FileU_HinhMinhHoa.PostedFile.InputStream;
                int fileLength = FileU_HinhMinhHoa.PostedFile.ContentLength;
                byte[] imageFile = new byte[fileLength];

                //			preFileName.Value = ft_file.PostedFile.FileName.ToString();
                if (FileU_HinhMinhHoa.FileName != "")
                {
                    int n = fileStream.Read(imageFile, 0, fileLength);
                }

                clsWebShop cls = new clsWebShop();
                PccMsg msg=new PccMsg();
                string UserID=Session["AdminUserID"].ToString();
                msg.CreateFirstNode("UserID",UserID);
                msg.CreateFirstNode("Ext_no",System.IO.Path.GetExtension(FileU_HinhMinhHoa.FileName).Replace(".",""));            
                msg.CreateFirstNode("UpdID",Session["AdminUserID"].ToString());
                cls.Ins_Upd_shr_UserSign(msg.GetXmlStr, imageFile);
            }
            BindData();
        }
        else
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('Chọn file hình ảnh')</script>");
            return;
        }
    }
}
